# Contributor: André Klitzing <aklitzing@gmail.com>
# Maintainer: André Klitzing <aklitzing@gmail.com>
pkgname=ripgrep
pkgver=12.1.1
pkgrel=1
pkgdesc="ripgrep combines the usability of The Silver Searcher with the raw speed of grep"
url="https://github.com/BurntSushi/ripgrep"
arch="all !s390x !mips !mips64" # limited by cargo
license="MIT OR Public-Domain"
makedepends="cargo asciidoc pcre2-dev"
checkdepends="xz"
subpackages="$pkgname-doc
	$pkgname-bash-completion:bashcomp:noarch
	$pkgname-zsh-completion:zshcomp:noarch
	$pkgname-fish-completion::noarch
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/BurntSushi/ripgrep/archive/$pkgver.tar.gz"

build() {
	cargo build --release --locked --features 'pcre2'
}

check() {
	cargo test --release --locked --features 'pcre2'
}

package() {
	install -Dm755 "target/release/rg" "$pkgdir/usr/bin/rg"
	install -Dm644 "target/release/build/ripgrep-"*/out/rg.1 \
		"$pkgdir/usr/share/man/man1/rg.1"

	install -Dm644 "$builddir"/target/release/build/ripgrep-*/out/rg.fish \
		-t "$pkgdir"/usr/share/fish/completions
}

bashcomp() {
	depends=""
	pkgdesc="Bash completions for $pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel bash-completion"
	mkdir -p "$subpkgdir"/usr/share/bash-completion/completions/
	install -Dm644 "$builddir/target/release/build/ripgrep-"*/out/rg.bash \
		"$subpkgdir/usr/share/bash-completion/completions/rg"
}

zshcomp() {
	depends=""
	pkgdesc="Zsh completions for $pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel zsh"

	mkdir -p "$subpkgdir"/usr/share/zsh/site-functions/
	install -Dm644 "$builddir/complete/_rg" \
		"$subpkgdir/usr/share/zsh/site-functions/_rg"
}

sha512sums="9e2a16043be6c7727d49a44f6db7fdb41413efc869139186729985ff86dee5c6531c663352f4019b730eb3a6c46f26d46df3738d4a0cbbc39ab773f320eb9e59  ripgrep-12.1.1.tar.gz"
